package cn.yunhe.user.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.yunhe.entity.User;
import cn.yunhe.user.service.UserService;

@Controller
@RequestMapping("/user")
public class UserWeb {
	@Autowired
	private UserService userService;
	
	@RequestMapping("/toLogin")
	public String login(User user,HttpServletRequest request) {
		
		List<User> userList = userService.selectUserByNamePassword(user.getUsername(), user.getPassword());
		if(userList != null) {
			if(!userList.isEmpty()) {
				System.out.println("jinrul-----------");
				request.getSession().setAttribute("user", userList.get(0));
				return "index";
			}
			
			return "login";
		}
		return "login";
	}
	
	@RequestMapping("/login")
	public String login() {
		return "login";
	}
	
}
